<?php
namespace app\index\controller;

use think\Controller;
use think\Db;
use think\Request;

class Index extends Controller
{

    private function add($a = 8, $b = 8){
        return $a*$b;
    }

    public function index(){

    }

    public function index1($name = 'World')
    {
        //return 'hello ,'. $name .' !';

        //$this->assign('name', $name);
        //return $this->fetch();

        $urls = url('blog/get','id=10');
        $this->assign('urls',$urls);


        $data = Db::name('data')->find();
        $this->assign('users', $data);
        return $this->fetch();
    }

    public function hello(Request $request){

        //$request = Request::instance();

        //echo 'url:'.$request->url().'<br/>';

        echo '请求的参数';
        //dump($request->param());
        //简化写法
        dump(input());


        return 'name:'.input('name');
    }

    public function hello2(Request $request){
        echo 'GET参数:';
        dump($request->get());
        dump(input('get.'));

        echo 'get name:';
        dump($request->get('name'));
        dump(input('get.name'));

        echo 'post name:';
        dump($request->post('name'));
        dump(input('post.name'));

        echo 'cookie:';
        dump($request->cookie('name'));
        dump(input('cookie.name'));

        echo '文件上传 image:';
        dump($request->file('image'));
        dump(input('file.image'));
        echo '<hr/>';

        echo '请求：'.$request->method().'<br/>';
        echo '资源类型'.$request->type().'<br/>';
        echo 'ip:'.$request->ip().'<br/>';
        //echo '是否ajax:'.$request->isAjax().'<br/>';
        echo 'ajax:'.var_export($request->isAjax(),true).'<br/>';

        echo '路由：';
        echo dump($request->routeInfo());
        echo '调度信息：';
        echo dump($request->dispatch());
    }

    public function hello3(){
        $data =['name'=>'zhangsan','age'=>18,'score'=>'88.5'];
        //return $data;

        return json($data);
    }

    protected  function hello1(){
        return 'protected';
    }

}
